package com.hzhjhh.view.manageView.menus.storage.inReturnGoods;

import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import com.hzhjhh.init.dialog.Mytable;
import com.hzhjhh.means.Select_Means;
import com.hzhjhh.view.manageView.menus.storage.InReturnGoodsDialog;
import com.hzhjhh.view.manageView.menus.storage.constant.ShowConstants;

/**
 * 菜单栏初始化-仓库-进/退货-确定按钮
 * 
 * @author 12083
 *
 */
public class EnsureBt {

	/**
	 * 按钮
	 */
	public static JButton btInit(InReturnGoodsDialog inReturnGoodsDialog) {
		
		JButton ensure = new JButton();
		ensure.setBounds(72, 436, 81, 30);
		ensure.setText("确   认");
		ensure.setSelectedIcon(null);
		ensure.addActionListener(event -> {
			JTextField jTextField1 = inReturnGoodsDialog.getTxfTime();
			JTextField jTextField2 = inReturnGoodsDialog.getTxfMerchandiseCode();
			JTextField jTextField3 = inReturnGoodsDialog.getJTextField3();
			JTextField jTextField4 = inReturnGoodsDialog.getJTextField4();
			JTable jTable1 = inReturnGoodsDialog.getJTable1();
			Vector vector1 = inReturnGoodsDialog.getVector1();
			JScrollPane jScrollPane1 = inReturnGoodsDialog.getJScrollPane1();
			
			Vector select1 = Select_Means.Select_sort2(jTextField2.getText());
	        if (select1.size() == 0) {
	            JOptionPane.showMessageDialog(inReturnGoodsDialog, "商品不存在", "错误",
	                    JOptionPane.ERROR_MESSAGE);
	            return;
	        }
	        Vector select2 = (Vector) select1.get(0);
	        Vector vector = new Vector();
	        double allMoney = 0;
	        vector.add(jTextField2.getText());
	        vector.add(select2.get(3).toString());
	        vector.add(jTextField3.getText());
	        vector.add(jTextField4.getText());
	        vector.add(jTextField1.getText());

	        try {
	            Double num = new Double(jTextField3.getText());
	            Double money = new Double(jTextField4.getText());
	            allMoney = (int) (num * money * 100) / 100.0;
	        } catch (Exception ex) {
	            JOptionPane.showMessageDialog(inReturnGoodsDialog, "输入的数字有误", "错误",
	                    JOptionPane.ERROR_MESSAGE);
	            return;
	        }
	        Double dd = new Double(allMoney);
	        vector.add(dd.toString());
	        vector1.add(vector);
	        jTable1 = Mytable.maketable(vector1, ShowConstants.IN_RETURN_GOODS_HEAD_NAME); //显示内容
	        jScrollPane1.getViewport().add(jTable1); //把表装入容器
		});
		return ensure;
	}
}
